<?php

namespace app\common\dao\system;

use app\common\model\system\SystemGroup as model;
use app\common\dao\BaseDao;

class SystemGroupDao extends BaseDao
{
    /**
    * 设置模型
    * @return model
    */
    protected function getModel(): string
    {
        return model::class;
    }

    public function all()
    {
        return ($this->getModel())::getDB()->select();
    }

    public function count()
    {
        return ($this->getModel())::getDB()->count();
    }

    public function page($page, $limit)
    {
        return ($this->getModel())::getDB()->page($page, $limit);
    }

    public function keyExists($key, ?int $except = null): bool
    {
        return parent::fieldExists('group_key', $key, $except);
    }

    public function fields($id)
    {
        return json_decode(($this->getModel())::getDB()->where('group_id', $id)->value('fields'), true);
    }

    public function keyById(string $key)
    {
        return ($this->getModel())::getDB()->where('group_key', $key)->value('group_id');
    }



}